package com.dreamthen.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author zengms
 * @Date 2023-11-12 10:47:25
 **/
@Controller
@RequestMapping("/user")
public class UserController {

    @GetMapping("/login")
    public String login() {
        return "login";
    }

    @PostMapping("/login")
    public String userLogin(HttpServletRequest request, HttpSession httpSession) {
        String loginName = request.getParameter("loginName");
        if(null==loginName || "".equals(loginName)){
            request.setAttribute("error","登录账号不能为空");
            return "error";
        }
        System.out.println("***loginName="+loginName);
        //数据库查询
        //        //校验用户信息
        httpSession.setAttribute("userName",loginName);
        return "admin";
    }
}
